
package graphics2d;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;


public class KeyboardController implements KeyListener {

    private final Scene scene;
    private final Object object;
    
    private final int speed = 10;
    
    private static final char LEFT = '4';
    private static final char RIGHT = '6';
    private static final char UP = '8';
    private static final char DOWN = '2';
    private static final char ROTATE_POS = '1';
    private static final char ROTATE_NEG = '3';
    private static final char ROTATE_PP_POS = '7';
    private static final char ROTATE_PP_NEG = '9';
    private static final char SCALE_POS = '+';
    private static final char SCALE_NEG = '-';
    
    public KeyboardController(Scene scene, Object object) {
        
        this.scene = scene;
        this.object = object;
        
    }
    
    @Override
    public void keyTyped(KeyEvent e) {
        
        switch (e.getKeyChar()) {
            case LEFT: object.transfer(-0.2*speed, 0);
                       break;
            case RIGHT: object.transfer(0.2*speed, 0);
                        break;
            case UP: object.transfer(0, 0.2*speed);
                     break;
            case DOWN: object.transfer(0, -0.2*speed);
                       break;
            case ROTATE_POS: object.rotate(1*speed);
                             break;
            case ROTATE_NEG: object.rotate(-1*speed);
                             break;
            case SCALE_POS: object.scale(1.1, 1.1);
                            break;
            case SCALE_NEG: object.scale(0.9, 0.9);
                            break;
            case ROTATE_PP_POS: object.rotatePP(1*speed);
                                break;
            case ROTATE_PP_NEG: object.rotatePP(-1*speed);
                                break;
        }
        scene.repaint();
        
        
    }

    @Override
    public void keyPressed(KeyEvent e) {
        
    }

    @Override
    public void keyReleased(KeyEvent e) {
        
    }
    
}
